<template>
 <div style="background-color: #eee;height: 100%;">
    <van-form @submit="onSubmit">
      <van-field
        v-model="msg2"
        name="信息"
        clearable
      />
      <div style="margin: 16px; font-size: 22px;">
        <van-button  block type="info" native-type="submit" color="#37B5B5">保存</van-button>
      </div>
  </van-form>
 </div>
</template>

<script>
import { Cell, CellGroup, Icon, Popup ,Picker, Field, Form,Button  } from 'vant';
import { getValue, setValue, setObject, clear } from "@/utils/auth";
import { postHandle, getHandle } from "@/api";
 export default {
  name: '',
  components: {
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Icon.name]: Icon,
    [Popup.name]: Popup,
    [Button.name]: Button,
    [Field.name]: Field,
    [Form.name]: Form,
  },
  data () {
   return {
     flag: getValue('expert-flag'),
     obj: JSON.parse(getValue('expert-obj')),
     updataData: {},
     msg2: ""
   }
  },

  created() {
    this.msg()
  },
  methods: {
    msg() {
      if(this.flag == '个人简介'){
        this.msg2 = this.obj.expertIntroduce
      }
      if(this.flag == '详细地址'){
        this.msg2 = this.obj.address
      }
      if(this.flag == '工作单位'){
        this.msg2 = this.obj.workUnit
      }
      if(this.flag == '个人成就'){
        this.msg2 = this.obj.achievement
      }
      if(this.flag == '身份证号码'){
        this.msg2 = this.obj.idCardNum
      }
      if(this.flag == '普通昵称'){
        this.msg2 = this.obj.niceName
      }
      if(this.flag == '普通真实姓名'){
        this.msg2 = this.obj.name
      }
      if(this.flag == '普通身份证号'){
        this.msg2 = this.obj.idCardNo
      }
      if(this.flag == '普通邮箱'){
        this.msg2 = this.obj.contactEmail
      }
    },
    onSubmit() {
      // 修改资料保存
      if(this.flag == '个人简介') {
        this.updataData.expertIntroduce  = this.msg2
        this.updateInfo()
      }
      if(this.flag == '详细地址') {
        this.updataData.address  = this.msg2
        this.updateInfo()
      }
      if(this.flag == '工作单位') {
        this.updataData.workUnit  = this.msg2
        this.updateInfo()
      }
      if(this.flag == '个人成就') {
        this.updataData.achievement  = this.msg2
        this.updateInfo()
      }
      if(this.flag == '身份证号码') {
        this.updataData.idCardNum  = this.msg2
        this.updateInfo()
      }
      if(this.flag == '普通昵称') {
        this.updataData.niceName  = this.msg2
        this.updateInfoPT()
      }
      if(this.flag == '普通真实姓名') {
        this.updataData.name  = this.msg2
        this.updateInfoPT()
      }
      if(this.flag == '普通身份证号') {
        this.updataData.idCardNo  = this.msg2
        this.updateInfoPT()
      }
      if(this.flag == '普通邮箱') {
        this.updataData.contactEmail  = this.msg2
        this.updateInfoPT()
      }
    },
    // 修改接口 专家
    updateInfo() {
      postHandle('/agri/api/common/subjectInfoExpert/update4App', {
        ...this.updataData,
        userId: getValue('loginUserId')
      }).then(res => {
        this.$bridge.call('base.closePage')
        // this.$bridge.call('myProfile_expert')
      })
    },
    // 修改接口 普通
    updateInfoPT() {
      postHandle('/agri/api/common/tenant/update4Person', {
        ...this.updataData,
        id: getValue('loginUserId')
      }).then(res => {
        // this.$bridge.call('base.closed')
        this.$bridge.call('base.closePage')
      })
    },
  },
  }
</script>

<style lang="scss" scoped>

</style>
